package com.zxm.web.controller.oss;

import com.zxm.common.core.domain.AjaxResult;
import com.zxm.oss.context.UploadStrategyContext;
import com.zxm.oss.enums.FilePathEnum;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author silence.Z
 * @Date 2022/6/15 10:48
 * @PackageName:com.zxm.web.controller.oss
 * @ClassName: QiniuossController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("oss/qiniu")
public class QiniuOssController {
	/*@Autowired
	QiniuServiceImpl qiniuService;

	@PostMapping("/upload")
	public AjaxResult upload(@RequestParam("file") MultipartFile uploadFile, HttpServletRequest req) {
		if (!uploadFile.isEmpty()) {
			return AjaxResult.success("上传成功!",qiniuService.saveFile(uploadFile));
		}
		return AjaxResult.error("上传失败!");
	}

	@PostMapping("/uploads")
	public AjaxResult upload(@RequestParam("files") MultipartFile[] uploadFiles, HttpServletRequest req) {
		if (!ObjectUtils.isEmpty(uploadFiles) && uploadFiles.length > 0) {
			return AjaxResult.success("上传成功!",qiniuService.saveFile(uploadFiles));
		}
		return AjaxResult.error("上传失败!");
	}*/

	@Autowired
	private UploadStrategyContext uploadStrategyContext;

	@PostMapping("/upload")
	public AjaxResult upload(MultipartFile file) {
		if (!file.isEmpty()) {
			return AjaxResult.success("上传成功!",uploadStrategyContext.executeUploadStrategy(file, FilePathEnum.PHOTO.getPath()));
		}
		return AjaxResult.error("上传失败!");
	}
}
